//
//  NavigationBarModifier.swift
//  Kosspot
//
//  Created by 李鑫 on 2025/7/1.
//

import SwiftUI
/*
extension View {
    func customNavigationBar(title: String,
                           titleColor: Color = .white,
                           titleFont: Font = .system(size: 18, weight: .semibold),
                           backButtonAction: @escaping () -> Void) -> some View {
        self
            .navigationBarBackButtonHidden(true)
            .toolbar {
                ToolbarItem(placement: .principal) {
                    Text(title)
                        .foregroundColor(titleColor)
                        .font(titleFont)
                }
            }
            .navigationBarItems(leading: Button(action: backButtonAction) {
                Image("back")
                    .foregroundColor(titleColor)
            })
            
    }
}  */

extension View {
    func customNavigationBar(
        title: String,
        titleColor: Color = .white,
        titleFont: Font = .system(size: 18, weight: .semibold),
        backButtonAction: @escaping () -> Void,
        backgroundColor: UIColor  //= .clear
    ) -> some View {
        // 设置导航栏外观
        let appearance = UINavigationBarAppearance()
                appearance.configureWithOpaqueBackground() // 禁用透明
                appearance.backgroundColor = backgroundColor   //Color(hex: "#0A0A0A")  //   (Color(hex: "#0A0A0A"))//.clear // 使用系统背景色
                UINavigationBar.appearance().standardAppearance = appearance
                UINavigationBar.appearance().scrollEdgeAppearance = appearance
        return self
            .navigationBarBackButtonHidden(true)
            .navigationBarTitleDisplayMode(.inline)
            .toolbar {
                ToolbarItem(placement: .principal) {
                    Text(title)
                        .foregroundColor(titleColor)
                        .font(titleFont)
                }
            }
            .navigationBarItems(leading: Button(action: backButtonAction) {
                Image("back")
                    .foregroundColor(titleColor)
            })
    }
}
